<template>
  <div style="width: 100%; height: 100%">
    <el-header class="el-header">
      <div class="header-back-container">
        <div class="el-page-header">
          <div class="el-page-header__left" @click="onBack">
            <i class="el-icon-back"></i>
            <div class="el-page-header__title">返回</div>
          </div>
          <div class="el-page-header__content">
            <div class="title-box">
              <div class="title">
                {{ editData && editData.id ? "编辑巡查任务" : "新增巡查任务" }}
              </div>
            </div>
          </div>
        </div>
      </div>
    </el-header>
    <el-main style="height: calc(100% - 60px - 60px); overflow-y: auto">
      <div class="info-title">基础信息</div>
      <el-form
        :model="formBasic"
        :rules="rulesBasic"
        inline
        ref="refFormBasic"
        label-width="110px"
        style="margin: 0px 8px; padding: 0px 20px"
      >
        <el-form-item label="任务名称" prop="mainTaskName">
          <el-input
            v-model.trim="formBasic.mainTaskName"
            placeholder="请输入"
            maxlength="30"
            style="width: 340px"
            size="small"
            clearable
          ></el-input>
        </el-form-item>
      </el-form>
      <div class="info-title">巡查任务时间</div>
      <el-form
        :model="formTime"
        :rules="rulesTime"
        inline
        ref="refFormTime"
        label-width="90px"
        style="margin: 0px 8px; padding: 0px 20px"
      >
        <el-row>
          <el-col :span="24">
            <el-form-item label="任务时间"> </el-form-item>
            <el-form-item label="启动时间" prop="startTime">
              <el-date-picker
                v-model="formTime.startTime"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 340px"
                size="small"
                placeholder="选择日期"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="时段"></el-form-item>
            <div style="display: inline-block">
              <div class="time-box">
                <div class="time-box_item">
                  <div
                    v-for="(item, index) in formTime.timeIntervalList"
                    :key="index"
                  >
                    <el-form-item
                      label=""
                      :prop="`timeIntervalList[${index}].startTimeInterval`"
                    >
                      <el-time-picker
                        v-model="
                          formTime.timeIntervalList[index].startTimeInterval
                        "
                        :picker-options="{
                          selectableRange: optionalTime,
                        }"
                        @change="() => validateTime(index)"
                        value-format="HH:mm:ss"
                        format="HH:mm"
                        placeholder="选择开始时间"
                        size="small"
                        popper-class="date-style"
                      ></el-time-picker>
                      <!-- :picker-options="startPickerOptions[index]" -->
                    </el-form-item>
                    <el-form-item
                      label=""
                      :prop="`timeIntervalList[${index}].endTimeInterval`"
                    >
                      <el-time-picker
                        v-model="
                          formTime.timeIntervalList[index].endTimeInterval
                        "
                        :picker-options="{
                          selectableRange: optionalTime,
                        }"
                        @change="() => validateTime(index)"
                        value-format="HH:mm:ss"
                        format="HH:mm"
                        placeholder="选择结束时间"
                        size="small"
                        popper-class="date-style"
                      ></el-time-picker>
                      <!-- :picker-options="endPickerOptions[index]" -->
                      <!-- {{ optionalTime }} -->
                    </el-form-item>
                    <i
                      @click="onDelTime(item, index)"
                      class="iconfont shanchu tableBtnIcon timeDelIcon"
                      :style="{
                        cursor:
                          formTime.timeIntervalList.length == 1
                            ? 'not-allowed'
                            : 'pointer',
                      }"
                    ></i>
                  </div>
                </div>
                <div
                  class="add-time"
                  @click="addTime"
                  :style="{
                    cursor:
                      formTime.timeIntervalList.length == 5
                        ? 'not-allowed'
                        : 'pointer',
                  }"
                >
                  <i class="el-icon-circle-plus-outline"></i>
                  <span style="margin: 0 5px; font-size: 14px">添加时段</span>
                  <span style="font-size: 14px"
                    >({{ formTime.timeIntervalList.length }}/5)</span
                  >
                </div>
              </div>
            </div>
          </el-col>
          <el-col :span="24">
            <el-form-item label="重复频率"></el-form-item>
            <el-form-item
              label=""
              props="taskCycle.repetitiveFrequency.isRepeat"
            >
              <el-select
                size="small"
                style="width: 340px"
                v-model="formTime.taskCycle.repetitiveFrequency.isRepeat"
                placeholder="重复"
                filterable
              >
                <el-option
                  v-for="item in repeatList"
                  :label="item.label"
                  :value="item.value"
                  :key="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <span
              class="timeDelIcon"
              style="margin: 0 10px 0 26px; font-size: 14px"
              >每</span
            >
            <el-form-item label="" props="taskCycle.repetitiveFrequency.step">
              <el-input
                v-model="formTime.taskCycle.repetitiveFrequency.step"
                type="number"
                size="small"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
            <el-form-item label="" props="taskCycle.repetitiveFrequency.unit">
              <el-select
                size="small"
                style="width: 340px"
                v-model="formTime.taskCycle.repetitiveFrequency.unit"
                filterable
              >
                <el-option
                  v-for="item in unitList"
                  :label="item.label"
                  :value="item.value"
                  :key="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col
            :span="24"
            v-if="
              formTime.taskCycle.repetitiveFrequency.unit == 2 ||
              formTime.taskCycle.repetitiveFrequency.unit == 3
            "
          >
            <el-form-item label="重复周期"></el-form-item>
            <!-- 周 -->
            <div
              class="cycle"
              v-if="formTime.taskCycle.repetitiveFrequency.unit == 2"
            >
              <div class="cycle-box">
                <div
                  v-for="(item, index) in cycleWeeks"
                  :key="item.value"
                  @click="cycleClick(item, index, 'week')"
                  :class="{
                    'selected-cycle': selectedWeeks.includes(item.value),
                  }"
                  class="cycle-common"
                >
                  {{ item.label }}
                </div>
              </div>
            </div>

            <!-- 月 -->
            <div
              class="cycle"
              v-if="formTime.taskCycle.repetitiveFrequency.unit == 3"
            >
              <div class="cycle-box">
                <div
                  v-for="(item, index) in cycleMonths"
                  :key="item.value"
                  @click="cycleClick(item, index, 'month')"
                  :class="{
                    'selected-cycle': selectedMonths.includes(item.value),
                  }"
                  class="cycle-common"
                >
                  {{ item.label }}
                </div>
              </div>
            </div>
          </el-col>
          <el-col :span="24">
            <el-form-item label="截止日期"></el-form-item>
            <el-form-item label="" props="taskCycle.isEnd">
              <el-radio-group v-model="formTime.taskCycle.isEnd">
                <el-radio :label="1">永久有效</el-radio>
                <el-radio :label="2">有效日期</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item
              label=""
              props="taskCycle.endTime"
              style="margin-left: 20px"
              v-if="formTime.taskCycle.isEnd == 2"
            >
              <el-date-picker
                v-model="formTime.taskCycle.endTime"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 340px"
                size="small"
                placeholder="选择日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="info-title">巡查点</div>
      <div class="associated-devices">
        <div class="header" style="margin-bottom: 10px">
          <div class="header_left">
            <el-button
              class="el_button"
              size="small"
              icon="el-icon-plus"
              @click="addClick"
            >
              新增
            </el-button>
          </div>
          <div class="header_right"></div>
        </div>
        <div class="content">
          <el-table
            :data="dataList"
            class="table"
            max-height="400"
            :header-cell-style="headerStyle"
            ref="refTable"
            row-key="deviceCode"
          >
            <el-table-column
              align="center"
              prop="mainTaskName"
              label="巡查点"
              min-width="100"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              prop="itemsName"
              label="巡查项分类"
              min-width="100"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              align="center"
              prop="categoryName"
              label="巡查项"
              min-width="100"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              align="center"
              label="巡查员"
              min-width="100"
              show-overflow-tooltip
            >
              刘先生
            </el-table-column>
            <el-table-column align="center" label="操作" width="150">
              <template slot-scope="scope">
                <el-tooltip
                  class="item"
                  effect="dark"
                  content="删除"
                  placement="bottom"
                >
                  <i
                    @click="onDel(scope.row)"
                    class="iconfont shanchu tableBtnIcon"
                  ></i>
                </el-tooltip>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div style="height: 14px"></div>
    </el-main>
    <el-footer class="dialog-footer">
      <el-button size="small" @click="closeDialog">取 消</el-button>
      <el-button
        size="small"
        type="primary"
        @click="onSubmit"
        v-preventReClick="1000"
        >确 定</el-button
      >
    </el-footer>
    <choseDevice
      ref="refChoseDevice"
      :orgId="formBasic.orgId"
      :unitId="formBasic.unitId"
      :buildingId="formBasic.buildingId"
      :floorId="formBasic.floorId"
      :spaceId="formBasic.spaceId"
      :treeData="treeData"
      @getDevices="getDevices"
    />
  </div>
</template>

<script>
import tableStyleMixin from "../mixins/table-style";
import { mapState } from "vuex";
import { reqOrgList } from "@/api/api";
import choseDevice from "./choseDevice.vue";
import TreeSearchAdd from "@components/TreeSearchAdd.vue";
import loadMore from "@mixin/loadMore";

export default {
  name: "",
  props: ["showIndex", "editData"],
  components: { TreeSearchAdd, choseDevice },
  watch: {
    showIndex(val) {
      if (JSON.stringify(this.editData) == "{}") {
        this.isEditInfo = false;
      } else {
        // 编辑
        this.isEditInfo = true;
      }
    },
  },
  mixins: [tableStyleMixin, loadMore],
  data() {
    return {
      isEditInfo: false,
      formBasic: {
        mainTaskName: "",
      },
      rulesBasic: {
        mainTaskName: [
          { required: true, message: "请输入任务名称", trigger: "blur" },
        ],
      },
      formTime: {
        startTime: "",
        timeIntervalList: [{ startTimeInterval: "", endTimeInterval: "" }],
        taskCycle: {
          isEnd: "",
          endTime: "",
          repetitiveFrequency: {
            isRepeat: "",
            step: 1,
            unit: 0,
          },
        },
      },
      rulesTime: {
        startTime: [
          { required: true, message: "请选择生产日期", trigger: "change" },
        ],
      },
      repeatList: [
        {
          label: "不重复",
          value: 0,
        },
        {
          label: "重复",
          value: 1,
        },
      ],
      unitList: [
        {
          label: "小时",
          value: 0,
        },
        {
          label: "天",
          value: 1,
        },
        {
          label: "周",
          value: 2,
        },
        {
          label: "月",
          value: 3,
        },
      ],
      cycleWeeks: [
        {
          label: "周一",
          value: 1,
        },
        {
          label: "周二",
          value: 2,
        },
        {
          label: "周三",
          value: 3,
        },
        {
          label: "周四",
          value: 4,
        },
        {
          label: "周五",
          value: 5,
        },
        {
          label: "周六",
          value: 6,
        },
        {
          label: "周日",
          value: 7,
        },
      ],
      cycleMonths: [
        {
          label: "1",
          value: 1,
        },
        {
          label: "2",
          value: 2,
        },
        {
          label: "3",
          value: 3,
        },
        {
          label: "4",
          value: 4,
        },
        {
          label: "5",
          value: 5,
        },
        {
          label: "6",
          value: 6,
        },
        {
          label: "7",
          value: 7,
        },
        {
          label: "8",
          value: 8,
        },
        {
          label: "9",
          value: 9,
        },
        {
          label: "10",
          value: 10,
        },
        {
          label: "11",
          value: 11,
        },
        {
          label: "12",
          value: 12,
        },
        {
          label: "13",
          value: 13,
        },
        {
          label: "14",
          value: 14,
        },
        {
          label: "15",
          value: 15,
        },
        {
          label: "16",
          value: 16,
        },
        {
          label: "17",
          value: 17,
        },
        {
          label: "18",
          value: 18,
        },
        {
          label: "19",
          value: 19,
        },
        {
          label: "20",
          value: 20,
        },
        {
          label: "21",
          value: 21,
        },
        {
          label: "22",
          value: 22,
        },
        {
          label: "23",
          value: 23,
        },
        {
          label: "24",
          value: 24,
        },
        {
          label: "25",
          value: 25,
        },
        {
          label: "26",
          value: 26,
        },
        {
          label: "27",
          value: 27,
        },
        {
          label: "28",
          value: 28,
        },
        {
          label: "29",
          value: 29,
        },
        {
          label: "30",
          value: 30,
        },
        {
          label: "31",
          value: 31,
        },
      ],
      dataList: [
        {
          mainTaskName: "测试点",
          itemsName: "设备1",
          itemsId: "1",
          categoryName: "类别1",
          categoryId: "1",
        },
      ],
      treeData: [],
      selectedWeeks: [], // 存储选中的周
      selectedMonths: [], // 存储选中的月日期
      startPickerOptions: [], // 添加初始值
      endPickerOptions: [], // 添加初始值
      optionalTime: ["00:00:00 - 23:59:00"],
      isAllTime: true,
    };
  },
  computed: {
    ...mapState(["user", "spacesManage"]),
  },
  methods: {
    // 新增时段
    addTime() {
      let indexItem =
        this.formTime.timeIntervalList[
          this.formTime.timeIntervalList.length - 1
        ];
      if (!indexItem.startTimeInterval || !indexItem.endTimeInterval)
        return this.$message.warning("请先选择完时间");
      if (this.formTime.timeIntervalList.length >= 5) {
        this.isBanAddTime = true;
        return;
      }
      this.isBanAddTime = false;
      // 新增时段初始化为全天未被占用的第一个可用时间段
      const newInterval = { startTimeInterval: "", endTimeInterval: "" };
      this.formTime.timeIntervalList.push(newInterval);
    },

    // 校验时段
    validateTime(index) {
      const item = this.formTime.timeIntervalList[index];
      // if (this.formTime.timeIntervalList.length == 1) {
      //   if (item.startTimeInterval && !item.endTimeInterval) {
      //     this.optionalTime = [`${item.startTimeInterval} - 23:59:00`];
      //   } else if (!item.startTimeInterval && item.endTimeInterval) {
      //     this.optionalTime = [`00:00:00 - ${item.endTimeInterval}`];
      //   } else {
      //     this.optionalTime = this.calculateFreeIntervals(
      //       this.formTime.timeIntervalList
      //     );
      //     console.log(this.optionalTime, "this.optionalTime");
      //   }
      //   return;
      // }
      this.optionalTime = this.calculateFreeIntervals(
        this.formTime.timeIntervalList
      );
      console.log(this.optionalTime, "this.optionalTime");
    },

    calculateFreeIntervals(busyIntervals) {
      const parseTime = (timeStr) => {
        if (!timeStr) return null;
        const [h, m] = timeStr.split(":").map(Number);
        return h * 60 + m;
      };

      const minutesToTime = (minutes) => {
        const h = Math.floor(minutes / 60)
          .toString()
          .padStart(2, "0");
        const m = (minutes % 60).toString().padStart(2, "0");
        return `${h}:${m}:00`;
      };

      const mergeIntervals = (intervals) => {
        if (intervals.length === 0) return [];
        intervals.sort((a, b) => a.start - b.start);
        const merged = [intervals[0]];
        for (let i = 1; i < intervals.length; i++) {
          const last = merged[merged.length - 1];
          const current = intervals[i];
          if (current.start <= last.end) {
            last.end = Math.max(last.end, current.end);
          } else {
            merged.push(current);
          }
        }
        return merged;
      };

      // 处理正常时间段
      const normalIntervals = busyIntervals
        .filter((i) => i.startTimeInterval && i.endTimeInterval)
        .map((i) => ({
          start: parseTime(i.startTimeInterval),
          end: parseTime(i.endTimeInterval),
          undone: false,
        }))
        .filter((i) => i.start <= i.end);

      let merged = mergeIntervals(normalIntervals);

      // 处理只有开始时间的时段
      busyIntervals
        .filter((i) => i.startTimeInterval && !i.endTimeInterval)
        .forEach((i) => {
          const start = parseTime(i.startTimeInterval);
          let end = 23 * 60 + 59;

          for (const m of merged) {
            if (m.start <= end && m.end >= start) {
              end = Math.min(end, m.start - 1);
            }
          }

          if (start <= end) {
            merged.push({ start: start + 1, end, undone: true });
            merged = mergeIntervals(merged);
          }
        });

      // 处理只有结束时间的时段
      busyIntervals
        .filter((i) => !i.startTimeInterval && i.endTimeInterval)
        .forEach((i) => {
          const endTime = parseTime(i.endTimeInterval);
          let start = 0;

          for (const m of merged) {
            if (m.start <= endTime && m.end >= start) {
              start = Math.max(start, m.end + 1);
            }
          }

          if (start <= endTime) {
            merged.push({ start, end: endTime - 1, undone: true });
            merged = mergeIntervals(merged);
          }
        });

      // 最终合并
      merged = mergeIntervals(merged);

      // 计算空闲时间
      const merge_copy = [];
      const merge_copy_undone = [];
      merged.forEach((item) => {
        if (!item.undone) {
          merge_copy.push(item);
        } else {
          merge_copy_undone.push(item);
        }
      });
      const free = [];
      // 首时间段前
      if (merged[0].undone && merged[0].start > 0) {
        free.push({ start: 0, end: merged[0].start - 1 });
      } else if (merge_copy[0]?.start > 0) {
        free.push({ start: 0, end: merge_copy[0].start - 1 });
      }
      // 中间间隙
      for (let i = 1; i < merge_copy.length; i++) {
        const prevEnd = merge_copy[i - 1].end;
        const currStart = merge_copy[i].start;
        if (prevEnd < currStart - 1) {
          free.push({ start: prevEnd + 1, end: currStart - 1 });
        }
      }
      // 末时间段后
      if (
        merge_copy.length > 0 &&
        merge_copy[merge_copy.length - 1].end < 1439
      ) {
        free.push({
          start: merge_copy[merge_copy.length - 1].end + 1,
          end: 1439,
        });
      }
      merge_copy_undone.forEach((item) => {
        free.push(item);
      });
      return free.map(
        (f) => `${minutesToTime(f.start)} - ${minutesToTime(f.end)}`
      );
    },
    // calculateFreeIntervals(busyIntervals) {
    //   // 将时间字符串转换为分钟数
    //   const parseTime = (timeStr) => {
    //     const [h, m] = timeStr.split(":").map(Number);
    //     return h * 60 + m;
    //   };

    //   // 将分钟数转换为HH:mm格式
    //   const minutesToTime = (minutes) => {
    //     const h = Math.floor(minutes / 60);
    //     const m = minutes % 60;
    //     return `${h.toString().padStart(2, "0")}:${m
    //       .toString()
    //       .padStart(2, "0")}:00`;
    //   };

    //   // 解析输入的对象数组
    //   const intervals = [];
    //   for (const interval of busyIntervals) {
    //     const start = parseTime(interval.startTimeInterval);
    //     const end = parseTime(interval.endTimeInterval);
    //     if (start <= end) {
    //       // 仅处理有效时间段
    //       intervals.push({ start, end });
    //     }
    //   }

    //   // 如果没有时间段，直接返回全天
    //   if (intervals.length === 0) return ["00:00:00 - 23:59:00"];

    //   // 按开始时间排序
    //   intervals.sort((a, b) => a.start - b.start);

    //   // 合并重叠或相邻的时间段
    //   const merged = [intervals[0]];
    //   for (let i = 1; i < intervals.length; i++) {
    //     const current = intervals[i];
    //     const last = merged[merged.length - 1];
    //     if (current.start <= last.end) {
    //       last.end = Math.max(last.end, current.end);
    //     } else {
    //       merged.push(current);
    //     }
    //   }

    //   // 计算空闲时间段
    //   const freeIntervals = [];

    //   // 起始空闲：第一个时间段之前
    //   if (merged[0].start > 0) {
    //     freeIntervals.push({
    //       start: 0,
    //       end: merged[0].start - 1,
    //     });
    //   }

    //   // 中间空闲：相邻时间段之间的间隙
    //   for (let i = 1; i < merged.length; i++) {
    //     const prevEnd = merged[i - 1].end;
    //     const currStart = merged[i].start;
    //     if (prevEnd < currStart - 1) {
    //       freeIntervals.push({
    //         start: prevEnd + 1,
    //         end: currStart - 1,
    //       });
    //     }
    //   }

    //   // 结束空闲：最后一个时间段之后
    //   const last = merged[merged.length - 1];
    //   if (last.end < 1439) {
    //     // 1439 = 23:59
    //     freeIntervals.push({
    //       start: last.end + 1,
    //       end: 1439,
    //     });
    //   }

    //   // 转换为时间字符串
    //   return freeIntervals.map(({ start, end }) => {
    //     return `${minutesToTime(start)} - ${minutesToTime(end)}`;
    //   });
    // },
    // 将时间字符串转换为分钟数
    timeToMinutes(time) {
      if (!time) return 0;
      const [hours, minutes] = time.split(":").map(Number);
      return hours * 60 + minutes;
    },

    // 删除时间段
    onDelTime(item, index) {
      if (this.formTime.timeIntervalList.length == 1) return;
      this.formTime.timeIntervalList.splice(index, 1);
    },
    // 获取子组件传过来的设备数据
    getDevices(data) {
      this.treeData = data;
      this.prepareData();
    },
    // 数据预处理
    prepareData(data) {
      // 扁平化数据
      this.dataList = this.treeData.flatMap((item) =>
        item.patrolCategory.map((child) => ({
          itemsName: item.itemsName,
          itemsId: item.id,
          categoryName: child.categoryName,
          categoryId: child.id,
        }))
      );

      // 生成合并规则
      this.calculateSpan();
    },

    // 生成合并规则数组
    calculateSpan() {
      this.spanArr = [];
      this.treeData.forEach((item) => {
        const length = item.patrolCategory.length;
        this.spanArr.push(length);
        for (let i = 1; i < length; i++) {
          this.spanArr.push(0);
        }
      });
    },

    // 合并单元格方法
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        const rowspan = this.spanArr[rowIndex];
        return { rowspan: rowspan, colspan: 1 };
      }
    },

    // 重复频率
    cycleClick(item, index, type) {
      if (type === "week") {
        const idx = this.selectedWeeks.indexOf(item.value);
        if (idx > -1) {
          this.selectedWeeks.splice(idx, 1);
        } else {
          this.selectedWeeks.push(item.value);
        }
      } else if (type === "month") {
        const idx = this.selectedMonths.indexOf(item.value);
        if (idx > -1) {
          this.selectedMonths.splice(idx, 1);
        } else {
          this.selectedMonths.push(item.value);
        }
      }
    },

    // 新增
    addClick() {
      this.$refs.refChoseDevice.dialogVisible = true;
    },
    // 删除
    onDel(row) {
      this.treeData.forEach((item, index) => {
        if (item.id == row.itemsId) {
          item.patrolCategory.forEach((item2, index2) => {
            if (item2.id == row.categoryId) {
              if (item.patrolCategory.length == 1) {
                this.treeData.splice(index, 1);
              } else {
                item.patrolCategory.splice(index2, 1);
              }
            }
          });
        }
      });
      this.prepareData();
    },

    onBack() {
      this.closeDialog();
    },
    async onSubmit() {
      this.$refs.refFormBasic.validate(async (valid) => {
        if (valid) {
          if (valid2) {
            // const submitData = {
            //   ...this.formBasic,
            //   taskCycle: {
            //     ...this.formTime.taskCycle,
            //     repetitiveFrequency: {
            //       ...this.formTime.taskCycle.repetitiveFrequency,
            //       selectedWeeks: this.selectedWeeks,
            //       selectedMonths: this.selectedMonths,
            //     },
            //   },
            // };

            // 验证所有时间段是否有效
            // const isValid = this.formTime.timeIntervalList.every((item) => {
            //   return (
            //     item.startTimeInterval &&
            //     item.endTimeInterval &&
            //     this.timeToMinutes(item.startTimeInterval) <
            //       this.timeToMinutes(item.endTimeInterval)
            //   );
            // });

            // let res;
            // this.formBasic.tenantId = this.user.tenantId;
            // this.formBasic.deviceList = this.dataList.map((item) => {
            //   return {
            //     type: item.type,
            //     deviceCode: item.type == 1 ? item.imei : item.deviceCode,
            //     id: item.id,
            //     productType:
            //       item && item.productType ? item.productType : item.deviceType,
            //     spaceName: item.spaceName,
            //   };
            // });
            // let addForm_copy = { ...this.formBasic, ...this.formMaintenance };
            // if (JSON.stringify(this.editData) != "{}") {
            //   res = await reqFireFacilityEdit(this.editData.id, addForm_copy);
            //   if (res.code !== 20000)
            //     return this.$modal.notifyWarning(res.message);
            //   this.$modal.notifySuccess("编辑成功");
            // } else {
            //   res = await reqFireFacilityAdd(addForm_copy);
            //   if (res.code !== 20000)
            //     return this.$modal.notifyWarning(res.message);
            //   this.$modal.notifySuccess("新增成功");
            // }
            // this.$parent.getDataList();
            this.closeDialog();
          }
        }
      });
    },
    closeDialog() {
      this.dataList = [];
      this.$parent.isShowRuleOperate = false;
    },
  },
};
</script>

<style scoped lang="less">
@import url("./fpdOperate.less");

::v-deep .el-time-spinner__item.active:not(.disabled) {
  color: #606266 !important;
}
</style>
